




/*
'===============================================================================
'  HNG.Portal.BL.TblLienKetWebManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblLienKetWebManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_LangId="LangId";
				
				public const String Field_TenLienKet="TenLienKet";
				
				public const String Field_Mota="Mota";
				
				public const String Field_Url="Url";
				
				public const String Field_Target="Target";
				
				public const String Field_TrangThai="TrangThai";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblLienKetWebManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_LangId,typeof(string));
			
						
			
			dt.Columns.Add(Field_TenLienKet,typeof(string));
			
						
			
			dt.Columns.Add(Field_Mota,typeof(string));
			
						
			
			dt.Columns.Add(Field_Url,typeof(string));
			
						
			
			dt.Columns.Add(Field_Target,typeof(string));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
			            
            return dt;			
		}
			
		public TblLienKetWebEntity Convert_Entity(TblLienKetWebEntity _TblLienKetWebEntity,TblLienKetWebEntity _TblLienKetWebEntity_XML)
		{	
			
				
			_TblLienKetWebEntity.Id= _TblLienKetWebEntity_XML.Id;
				
			_TblLienKetWebEntity.LangId= _TblLienKetWebEntity_XML.LangId;
				
			_TblLienKetWebEntity.TenLienKet= _TblLienKetWebEntity_XML.TenLienKet;
				
			_TblLienKetWebEntity.Mota= _TblLienKetWebEntity_XML.Mota;
				
			_TblLienKetWebEntity.Url= _TblLienKetWebEntity_XML.Url;
				
			_TblLienKetWebEntity.Target= _TblLienKetWebEntity_XML.Target;
				
			_TblLienKetWebEntity.TrangThai= _TblLienKetWebEntity_XML.TrangThai;
				
			
			return _TblLienKetWebEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblLienKetWebEntity Insert(TblLienKetWebEntity TblLienKetWebEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblLienKetWebEntity, true);
			}
			return TblLienKetWebEntity;
		}

		
		public TblLienKetWebEntity Insert(int Id, string LangId, string TenLienKet, string Mota, string Url, string Target, bool TrangThai)
		{
			TblLienKetWebEntity _TblLienKetWebEntity = new TblLienKetWebEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblLienKetWebEntity.Id = Id;
				_TblLienKetWebEntity.LangId = LangId;
				_TblLienKetWebEntity.TenLienKet = TenLienKet;
				_TblLienKetWebEntity.Mota = Mota;
				_TblLienKetWebEntity.Url = Url;
				_TblLienKetWebEntity.Target = Target;
				_TblLienKetWebEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblLienKetWebEntity, true);
			}
			return _TblLienKetWebEntity;
		}

		public TblLienKetWebEntity Insert(string LangId, string TenLienKet, string Mota, string Url, string Target, bool TrangThai)
		{
			TblLienKetWebEntity _TblLienKetWebEntity = new TblLienKetWebEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblLienKetWebEntity.LangId = LangId;
				_TblLienKetWebEntity.TenLienKet = TenLienKet;
				_TblLienKetWebEntity.Mota = Mota;
				_TblLienKetWebEntity.Url = Url;
				_TblLienKetWebEntity.Target = Target;
				_TblLienKetWebEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblLienKetWebEntity, true);
			}
			return _TblLienKetWebEntity;
		}

		public bool Update(TblLienKetWebEntity _TblLienKetWebEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblLienKetWebFields.Id == _TblLienKetWebEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblLienKetWebEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblLienKetWebEntity _TblLienKetWebEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblLienKetWebEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, string LangId, string TenLienKet, string Mota, string Url, string Target, bool TrangThai)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblLienKetWebEntity _TblLienKetWebEntity = new TblLienKetWebEntity(Id);
				if (adapter.FetchEntity(_TblLienKetWebEntity))
				{
				
					_TblLienKetWebEntity.LangId = LangId;
					_TblLienKetWebEntity.TenLienKet = TenLienKet;
					_TblLienKetWebEntity.Mota = Mota;
					_TblLienKetWebEntity.Url = Url;
					_TblLienKetWebEntity.Target = Target;
					_TblLienKetWebEntity.TrangThai = TrangThai;
					adapter.SaveEntity(_TblLienKetWebEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblLienKetWebEntity _TblLienKetWebEntity = new TblLienKetWebEntity(Id);
				if (adapter.FetchEntity(_TblLienKetWebEntity))
				{
					adapter.DeleteEntity(_TblLienKetWebEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblLienKetWebEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblLienKetWebEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLangId(string LangId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblLienKetWebEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTenLienKet(string TenLienKet)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.TenLienKet == TenLienKet);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblLienKetWebEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByMota(string Mota)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblLienKetWebEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByUrl(string Url)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Url == Url);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblLienKetWebEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTarget(string Target)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Target == Target);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblLienKetWebEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblLienKetWebEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblLienKetWebEntity SelectOne(int Id)
		{
			TblLienKetWebEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblLienKetWebEntity _TblLienKetWebEntity = new TblLienKetWebEntity(Id);
				if (adapter.FetchEntity(_TblLienKetWebEntity))
				{
					toReturn = _TblLienKetWebEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblLienKetWebCollection = new EntityCollection( new TblLienKetWebEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblLienKetWebCollection, null, 0, null);
			}
			return _TblLienKetWebCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblLienKetWebCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblLienKetWebCollection, filter, 0, null);
			}
			return _TblLienKetWebCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblLienKetWebCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLangId(string LangId)
		{
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblLienKetWebCollection, filter, 0, null);
			}
			return _TblLienKetWebCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLangIdRDT(string LangId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblLienKetWebCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTenLienKet(string TenLienKet)
		{
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.TenLienKet == TenLienKet);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblLienKetWebCollection, filter, 0, null);
			}
			return _TblLienKetWebCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTenLienKetRDT(string TenLienKet)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.TenLienKet == TenLienKet);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblLienKetWebCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByMota(string Mota)
		{
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblLienKetWebCollection, filter, 0, null);
			}
			return _TblLienKetWebCollection;
		}
		
		// Return DataTable
		public DataTable SelectByMotaRDT(string Mota)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblLienKetWebCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByUrl(string Url)
		{
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Url == Url);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblLienKetWebCollection, filter, 0, null);
			}
			return _TblLienKetWebCollection;
		}
		
		// Return DataTable
		public DataTable SelectByUrlRDT(string Url)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Url == Url);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblLienKetWebCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTarget(string Target)
		{
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Target == Target);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblLienKetWebCollection, filter, 0, null);
			}
			return _TblLienKetWebCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTargetRDT(string Target)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.Target == Target);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblLienKetWebCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblLienKetWebCollection, filter, 0, null);
			}
			return _TblLienKetWebCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblLienKetWebCollection = new EntityCollection(new TblLienKetWebEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblLienKetWebFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblLienKetWebCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
